package xxl.robotlegs.extensions.enhancedlogging.impl 
{
	import org.flashdevelop.utils.FlashConnect;
	import org.flashdevelop.utils.TraceLevel;
	import xxl.robotlegs.framework.api.IContext;
	import xxl.robotlegs.framework.api.ILogTarget;
	import xxl.robotlegs.framework.impl.log.LogLevel;
	import xxl.robotlegs.framework.impl.log.LogMessageParser;
	
	/**
	 * ...
	 * @author XXL
	 */
	public class FlashDevelopOutputTarget implements ILogTarget 
	{
		private const _messageParser:LogMessageParser = new LogMessageParser();
		private var _context:IContext;
		
		public function FlashDevelopOutputTarget(context:IContext) 
		{
			_context = context;
		}
		
		/* INTERFACE xxl.robotlegs.framework.api.ILogTarget */
		
		public function log(source:Object, level:int, timestamp:int, message:String, params:Array = null):void 
		{
			const msg:String = timestamp
				+ " " + LogLevel.NAME[level]
				+ " 所处上下文：" + _context
				+ " 日志注册源：" + source
				+ "\n" + _messageParser.parseMessage(message, params)
				+ "\n--------------------";
			var fLevel:int = TraceLevel.DEBUG;
			if (level == LogLevel.FATAL)
			{
				fLevel = TraceLevel.FATAL;
			}
			else if (level == LogLevel.ERROR)
			{
				fLevel = TraceLevel.ERROR;
			}
			else if (level == LogLevel.WARN)
			{
				fLevel = TraceLevel.WARNING;
			}
			else if (level == LogLevel.INFO)
			{
				fLevel = TraceLevel.INFO;
			}
			FlashConnect.trace(msg, fLevel);
			FlashConnect.flush();
		}
		
	}

}